package com.tobby.camel.camelinaction.chapter3.transform;

import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;

public class TransformTest extends CamelTestSupport {

	@Override
	protected RouteBuilder createRouteBuilder() {
		return new RouteBuilder() {

			@Override
			public void configure() throws Exception {
				from("direct:start").transform(body().regexReplaceAll("\n", "<br/>"))
						.to("mock:result");
			}
		};
	}

	@Test
	public void testTransform() throws InterruptedException {
		MockEndpoint mock = getMockEndpoint("mock:result");
		mock.expectedBodiesReceived("Hello<br/>How are you?");

		template.sendBody("direct:start", "Hello\nHow are you?");
		assertMockEndpointsSatisfied();
	}

}
